<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="media/layui/css/layui.css">
    <script src="media/layui/layui.js"></script>
    <script src="media/js/jquery.min.js"></script>
    <script src="media/js/echarts.min.js"></script>
</head>

<body background="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1599319786951&di=5c58fc85c3920a97c9397e31908d02cd&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Fback_pic%2F03%2F55%2F93%2F79579d98d81b2b1.jpg"
      style=" background-repeat: no-repeat; background-size: 100% 100%; background-attachment: fixed ">
<table class="layui-hide" id="exer" lay-filter="test"></table>

<div id="main" style="width: 600px;height:400px;"></div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

</body>
<script>
    layui.use('table', function(){
        //初始化table组件对象
        var table = layui.table;


        //渲染table
        table.render({
            //z找到table  id叫test的组件
            elem: '#exer'
            ,id:"exerTable"
            ,url:'exer/select.do'


            ,totalRow: true
            //这个很关键，就是解析 json数据库中数据的 一定要注意键值
            ,cols: [[
                {type:'checkbox',fixed: 'left'}
                ,{field:'id', title:'序号', unresize: true, sort: true, totalRowText: ''}
                ,{field:'category', title:'习题种类'}

                ,{field:'equestion', title:'习题'}
                ,{field:'eanswer', title:'答案' }
                ,{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}
            ]]
            ,page: true


        });

        //搜索框有效果的情况
        var  active = {
            reload: function(){
                //执行重载
                table.reload('exerTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }
        };

        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;

            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){

                    $.ajax({
                        type: "get",
                        url: "exer/delete.do?id="+ data.id,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 1) {
                                console.log(data.data)
                                alert(data.msg);
                                window.location.href= "exerciseslist.html"
                            } else {
                                layer.msg("删除失败")
                            }
                        }
                    })
                    obj.del();
                });
            }
        });


    });
</script>
<script>
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // 指定图表的配置项和数据
   var option = {
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
            orient: 'vertical',
            left: 10,
            data: ['习题种类', '习题', '答案']
        },
        series: [
            {
                name: '习题表饼状图分析',
                type: 'pie',
                radius: ['50%', '70%'],
                avoidLabelOverlap: false,
                label: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                },
                labelLine: {
                    show: false
                },
                data: [
                    {value: 4, name: '习题种类'},
                    {value: 11, name: '习题'},
                    {value: 11, name: '答案'},
                ]
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    $(function () {
        $.ajax({
            type:"get",
            url:"/showExercise.do",
            dataType:"json",
            success:function(data){
                console.log(data)

                option.legend.data=data.data.showExerciseList;
                option.series[0].data=data.data.showExerciseNumList;
                console.log(option)
                myChart.setOption(option)
            }
        })
    })
</script>
</html>
